package com.tourlaid.mamagerment.service.impl

import com.tourlaid.mamagerment.entity.Attention
import com.tourlaid.mamagerment.mapper.AttentionMapper
import com.tourlaid.mamagerment.service.AttentionService
import com.tourlaid.mamagerment.util.LoginUtil
import org.springframework.stereotype.Service
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/8/15.
 */
@Service("attentionService")
class AttentionServiceImpl : AttentionService {
    override fun queryByUserId(userId: Long): List<Map<String, Any?>> {
        return attentionMapper!!.queryByUserId(userId)
    }

    @Resource
    val attentionMapper: AttentionMapper? = null

    override fun getByUserIdAndTarget(userId: Long?, targetUserId: Long): Attention? {
        return attentionMapper!!.getByUserIdAndTarget(userId, targetUserId)
    }

    override fun attention(targetUserId: Long): Int {
        var attention = this.getByUserIdAndTarget(LoginUtil.userId, targetUserId)
        if (attention != null) return 1
        attention = Attention()
        attention.userId = LoginUtil.userId
        attention.targetUserId = targetUserId
        attention.creator = LoginUtil.userId
        attention.editor = LoginUtil.userId
        attentionMapper!!.insert(attention)
        return 1
    }

    override fun cancelAttention(targetUserId: Long) {
        attentionMapper!!.cancelAttention(LoginUtil.userId,targetUserId)
    }

}